#pragma once

#include <pthread.h>

// 利用类封装锁可以在定义变量时利用构造和析构自动加锁和解锁
class LockGuard
{
public:
    LockGuard(pthread_mutex_t* lock)
        :_lock(lock)
    {
        pthread_mutex_lock(_lock);
    }

    ~LockGuard()
    {
        pthread_mutex_unlock(_lock);
    }
private:
    pthread_mutex_t* _lock;
};